# This Python file uses the following encoding: utf-8
import datetime
from django.db import models
from django.db.models import exceptions

# Models.
class OrganisationType(models.Model):
    name = models.CharField(max_length=100,unique=True)
    description = models.CharField(max_length=100)

def AddOrganisationType(name):
    ot=OrganisationType(name=name)
    ot.save()

class Organisation(models.Model):
    name = models.CharField(max_length=100,unique=True)
    description = models.CharField(max_length=100)
    eid = models.CharField(max_length=100,unique=True)    
    otype = models.ForeignKey(OrganisationType)

def AddOrganisation(name,otype,eid):
    ot=OrganisationType.objects.get(name=otype)
    o=Organisation(name=name,eid=eid,otype=ot)
    o.save()

class Person(models.Model):
    name = models.CharField(max_length=100)
    eid = models.CharField(max_length=100,unique=True)    
	
def AddPerson(name,eid):
    p=Person(name=name,eid=eid)
    p.save()

class Position(models.Model):
    person = models.ForeignKey(Person)
    organisation = models.ForeignKey(Organisation)
    position = models.CharField(max_length=100)
	
def AddPosition(name,org,pos):
    p=Person.objects.get(name=name)
    o=Organisation.objects.get(name=org)
    pos=Position(person=p,organisation=o,position=pos)
    pos.save()

class OrganisationLog(models.Model):
    date = models.DateField()
    organisation = models.ForeignKey(Organisation)
    pos = models.PositiveIntegerField()
    neg = models.PositiveIntegerField()
    neut = models.PositiveIntegerField()

class PersonLog(models.Model):
    date = models.DateField()
    person = models.ForeignKey(Person)
    pos = models.PositiveIntegerField()
    neg = models.PositiveIntegerField()
    neut = models.PositiveIntegerField()

class OrganisationVote(models.Model):
    uid = models.CharField(max_length=100)    
    organisation = models.ForeignKey(Organisation)
    sentiment = models.IntegerField()

class PersonVote(models.Model):
    uid = models.CharField(max_length=100)    
    person = models.ForeignKey(Person)
    sentiment = models.IntegerField()

def ClearModel():
	OrganisationType.objects.all().delete()
	Organisation.objects.all().delete()
	Person.objects.all().delete()
	Position.objects.all().delete()
	OrganisationLog.objects.all().delete()
	PersonLog.objects.all().delete()
	OrganisationVote.objects.all().delete()
	PersonVote.objects.all().delete()
# Methods
    


